this.BX=this.BX||{};(function(t,e,i,n,a){"use strict";var s,r,l,o,u,c,h,v;function d(t,e){p(t,e);e.add(t)}function p(t,e){if(e.has(t)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function f(t,e,i){if(!e.has(t)){throw new TypeError("attempted to get private field on non-instance")}return i}var m=new WeakSet;var y=new WeakSet;var g=new WeakSet;var k=new WeakSet;var T=new WeakSet;var C=new WeakSet;var b=function(){function t(e){babelHelpers.classCallCheck(this,t);d(this,C);d(this,T);d(this,k);d(this,g);d(this,y);d(this,m);this.id=e.id?e.id:null;this.separator=i.Type.isBoolean(e.separator)?e.separator:true;this.items=i.Type.isArray(e.items)?e.items:[];this.popupMenu=null;this.isActive=i.Type.isBoolean(e.isActive)?e.isActive:false;this.isRestricted=i.Type.isBoolean(e.isRestricted)?e.isRestricted:false;this.panel=e.panel?e.panel:null;this.title=e.title?e.title:null;this.value=i.Type.isNumber(e.value)&&e.value!==undefined?e.value:null;this.titleOrder=null;this.valueOrder=null;this.color=e.color?e.color:null;this.parent=i.Type.isBoolean(e.parent)?e.parent:null;this.parentId=e.parentId?e.parentId:null;this.locked=false;this.type=i.Type.isString(e.type)?e.type.toLowerCase():null;this.eventsForActive=i.Type.isObject(e.eventsForActive)?e.eventsForActive:{};this.eventsForUnActive=i.Type.isObject(e.eventsForUnActive)?e.eventsForUnActive:{};if(i.Type.isObject(e.title)){this.title=e.title.value?e.title.value:null;this.titleOrder=i.Type.isNumber(e.title.order)?e.title.order:null}if(i.Type.isObject(e.value)){this.value=i.Type.isNumber(e.value.value)?e.value.value:null;this.valueOrder=i.Type.isNumber(e.value.order)?e.value.order:null}this.layout={container:null,value:null,title:null,cross:null,dropdownArrow:null,menuItem:null};this.counter=f(this,g,A).call(this);if(!f(this,y,L).call(this).isMultiselect()){f(this,m,w).call(this)}}babelHelpers.createClass(t,[{key:"getItems",value:function t(){return this.items}},{key:"hasParentId",value:function t(){return this.parentId}},{key:"updateValue",value:function t(e){if(i.Type.isNumber(e)){this.value=e;f(this,g,A).call(this).update(e);if(e===0){this.updateColor(this.parentId?"GRAY":"THEME")}}}},{key:"updateValueAnimate",value:function t(e){if(i.Type.isNumber(e)){this.value=e;f(this,g,A).call(this).update(e);f(this,g,A).call(this).show();if(e===0){this.updateColor(this.parentId?"GRAY":"THEME")}}}},{key:"updateColor",value:function t(e){if(i.Type.isString(e)){this.color=e;f(this,g,A).call(this).setColor(n.Counter.Color[e])}}},{key:"activate",value:function t(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this.isActive=true;if(this.parentId){var i=BX.findParent(this.getContainerMenu(),{className:"ui-counter-panel__popup-item"});if(i){i.classList.add("--active")}}else{this.getContainer().classList.add("--active")}if(e){a.EventEmitter.emit("BX.UI.CounterPanel.Item:activate",this)}}},{key:"deactivate",value:function t(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this.isActive=false;if(this.parentId){var i=BX.findParent(this.getContainerMenu(),{className:"ui-counter-panel__popup-item"});if(i){i.classList.remove("--active");i.classList.remove("--hover")}}else{this.getContainer().classList.remove("--active");this.getContainer().classList.remove("--hover")}if(e){a.EventEmitter.emit("BX.UI.CounterPanel.Item:deactivate",this)}}},{key:"getSeparator",value:function t(){return this.separator}},{key:"setEvents",value:function t(e){var i=this;if(!e){e=this.getContainer()}if(this.eventsForActive){var n=Object.keys(this.eventsForActive);var a=function t(){var a=n[s];e.addEventListener(a,(function(){if(i.isActive){i.eventsForActive[a]()}}))};for(var s=0;s<n.length;s++){a()}}if(this.eventsForUnActive){var r=Object.keys(this.eventsForUnActive);var l=function t(){var n=r[o];e.addEventListener(n,(function(){if(!i.isActive){i.eventsForUnActive[n]()}}))};for(var o=0;o<r.length;o++){l()}}}},{key:"isLocked",value:function t(){return this.locked}},{key:"lock",value:function t(){this.locked=true;this.getContainer().classList.add("--locked")}},{key:"unLock",value:function t(){this.locked=false;this.getContainer().classList.remove("--locked")}},{key:"getArrowDropdown",value:function t(){if(!this.layout.dropdownArrow){this.layout.dropdownArrow=i.Tag.render(s||(s=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-counter-panel__item-dropdown">\n\t\t\t\t\t<i></i>\n\t\t\t\t</div>\n\t\t\t'])))}return this.layout.dropdownArrow}},{key:"getContainerMenu",value:function t(){if(!this.layout.menuItem){this.layout.menuItem=i.Tag.render(r||(r=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t<span>\n\t\t\t\t\t","\n\t\t\t\t\t","\n\t\t\t\t\t","\n\t\t\t\t</span>\n\t\t\t"])),f(this,k,I).call(this),this.title,f(this,C,_).call(this))}return this.layout.menuItem}},{key:"getContainer",value:function t(){var e=this;if(!this.layout.container){var n=this.type?'id="ui-counter-panel-item-'.concat(this.type,'"'):"";var a=i.Type.isNumber(this.value);this.layout.container=i.Tag.render(l||(l=babelHelpers.taggedTemplateLiteral(["\n\t\t\t\t<div ",' class="ui-counter-panel__item">\n\t\t\t\t\t',"\n\t\t\t\t\t","\n\t\t\t\t\t","\n\t\t\t\t</div>\n\t\t\t"])),n,a?f(this,k,I).call(this):"",this.title?f(this,T,E).call(this):"",a?f(this,C,_).call(this):"");if(this.parent){this.layout.container=i.Tag.render(o||(o=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<div class="ui-counter-panel__item">\n\t\t\t\t\t\t',"\n\t\t\t\t\t\t","\n\t\t\t\t\t\t","\n\t\t\t\t\t</div>\n\t\t\t\t"])),this.title?f(this,T,E).call(this):"",a?f(this,k,I).call(this):"",f(this,C,_).call(this));f(this,C,_).call(this).addEventListener("click",(function(t){e.deactivate();t.stopPropagation()}));i.Dom.addClass(this.layout.container,"--dropdown")}if(!a){this.layout.container.classList.add("--string")}if(!a&&!this.eventsForActive&&!this.eventsForUnActive){this.layout.container.classList.add("--title")}if(!this.separator){this.layout.container.classList.add("--without-separator")}if(this.locked){this.layout.container.classList.add("--locked")}if(this.isActive){this.activate()}if(this.isRestricted){this.layout.container.classList.add("--restricted")}this.setEvents(this.layout.container);if(a&&this.items.length===0){if(!this.parent){this.layout.container.addEventListener("mouseenter",(function(){if(!e.isActive){e.layout.container.classList.add("--hover")}}));this.layout.container.addEventListener("mouseleave",(function(){if(!e.isActive){e.layout.container.classList.remove("--hover")}}));this.layout.container.addEventListener("click",(function(){e.isActive?e.deactivate():e.activate()}))}}if(this.parent){i.Dom.append(this.getArrowDropdown(),this.layout.container)}}return this.layout.container}}]);return t}();function w(){var t=this;a.EventEmitter.subscribe("BX.UI.CounterPanel.Item:activate",(function(e){var i=e.data.parentId===t.id;if(e.data!==t&&!i){t.deactivate()}}))}function L(){return this.panel}function A(t,e){if(!this.counter){this.counter=new n.Counter({value:this.value,color:this.color?n.Counter.Color[this.color.toUpperCase()]:this.parentId?n.Counter.Color.GRAY:n.Counter.Color.THEME,animation:false})}return this.counter}function I(){if(!this.layout.value){var t=this.isRestricted?i.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(['<div class="ui-counter-panel__item-lock"></div>']))):f(this,g,A).call(this).getContainer();this.layout.value=i.Tag.render(c||(c=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-counter-panel__item-value">\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),t);this.layout.value.style.setProperty("order",this.valueOrder)}return this.layout.value}function E(){if(!this.layout.title){this.layout.title=i.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-counter-panel__item-title">',"</div>\n\t\t\t"])),this.title);this.layout.title.style.setProperty("order",this.titleOrder)}return this.layout.title}function _(){if(!this.layout.cross){this.layout.cross=i.Tag.render(v||(v=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-counter-panel__item-cross">\n\t\t\t\t\t<i></i>\n\t\t\t\t</div>\n\t\t\t'])))}return this.layout.cross}var B,H,P;function F(t,e){O(t,e);e.add(t)}function O(t,e){if(e.has(t)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function S(t,e,i){if(!e.has(t)){throw new TypeError("attempted to get private field on non-instance")}return i}var U=new WeakSet;var X=new WeakSet;var M=new WeakSet;var N=function(){function t(e){babelHelpers.classCallCheck(this,t);F(this,M);F(this,X);F(this,U);this.target=i.Type.isDomNode(e.target)?e.target:null;this.items=i.Type.isArray(e.items)?e.items:[];this.multiselect=i.Type.isBoolean(e.multiselect)?e.multiselect:null;this.title=i.Type.isStringFilled(e.title)?e.title:null;this.container=null;this.keys=[];this.hasParent=[];this.childKeys=[]}babelHelpers.createClass(t,[{key:"isMultiselect",value:function t(){return this.multiselect}},{key:"getItems",value:function t(){return this.items}},{key:"getItemById",value:function t(e){if(e){var i=this.keys.indexOf(e);return this.items[i]}}},{key:"init",value:function t(){S(this,U,W).call(this);S(this,M,R).call(this)}}]);return t}();function W(){var t=this;this.items=this.items.map((function(e){e.panel=t;t.keys.push(e.id);if(e.parentId){t.hasParent.push(e.parentId)}return new b(e)}));this.hasParent.forEach((function(e){var i=t.keys.indexOf(e);t.items[i].parent=true}));this.items.map((function(e){if(e.parentId){var i=t.keys.indexOf(e.parentId);t.items[i].items.push(e.id)}}))}function j(){if(!this.container){var t="";if(this.title){t=i.Tag.render(B||(B=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<div class="ui-counter-panel__item-head">',"</div>\n\t\t\t\t"])),this.title)}this.container=i.Tag.render(H||(H=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-counter-panel ui-counter-panel__scope">',"</div>\n\t\t\t"])),t)}return this.container}function R(){var t=this;if(this.target&&this.items.length>0){this.items.map((function(n,a){if(n instanceof b){if(!n.hasParentId()){S(t,X,j).call(t).appendChild(n.getContainer());if(t.items.length!==a+1&&t.items.length>1){S(t,X,j).call(t).appendChild(i.Tag.render(P||(P=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t\t\t\t<div class="ui-counter-panel__item-separator ','"></div>\n\t\t\t\t\t\t\t'])),!n.getSeparator()?"--invisible":""))}}if(n.parent){n.getContainer().addEventListener("click",(function(){var i=[];n.getItems().forEach((function(e){var n=t.getItemById(e);var a={html:n.getContainerMenu(),className:"ui-counter-panel__popup-item menu-popup-no-icon ".concat(n.isActive?"--active":""),onclick:function t(){n.isActive?n.deactivate():n.activate()}};i.push(a)}));var a=new e.PopupMenuWindow({className:"ui-counter-panel__popup ui-counter-panel__scope",bindElement:n.getArrowDropdown(),autoHide:true,closeByEsc:true,items:i,angle:true,offsetLeft:6,offsetTop:-7,animation:"fading-slide",events:{onPopupShow:function t(){n.getContainer().classList.add("--hover");n.getContainer().classList.add("--pointer-events-none")},onPopupClose:function t(){n.getContainer().classList.remove("--hover");n.getContainer().classList.remove("--pointer-events-none");a.destroy()}}});a.show()}))}}}));i.Dom.clean(this.target);this.target.appendChild(S(this,X,j).call(this))}}t.CounterPanel=N;t.CounterItem=b})(this.BX.UI=this.BX.UI||{},BX.Main,BX,BX.UI,BX.Event);
//# sourceMappingURL=counterpanel.bundle.map.js